//
//  Director.m
//  RGATest
//
//  Created by Pablo Javier Bertola on 2/7/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "Director.h"
#import "Movie.h"


@implementation Director

@dynamic name;
@dynamic movies;

+(Director *)directorWithData:(NSString *)directorName inContext:(NSManagedObjectContext*)context
{
    Director *director = nil;
    
    NSFetchRequest* request = [[NSFetchRequest alloc]init];
    request.entity = [NSEntityDescription entityForName:@"Director" inManagedObjectContext:context];
    request.predicate = [NSPredicate predicateWithFormat:@"name = %@", directorName];
    
    NSError *error;
    director = [[context executeFetchRequest:request error:&error]lastObject];
    
    if (!error && !director) {
        director = [NSEntityDescription insertNewObjectForEntityForName:@"Director" inManagedObjectContext:context];
        director.name = directorName;
        
    }
    return director;
}
@end
